var ns, app, dialog, toast;
app = new Vue({
    el: '#app',
    data: {
        list: [],
        form: {
            ID:0,
            pageindex: 0,
            pagesize: 10,
            isFirstLoad: 1,
            keywords: '',
            status:2, //状态（0-通知我的 1-我发起的)
            IsRead:false,//仅看已读1  未读0
        },
        current_item_length: 0,
        is_searching: false,
        scroll_top: 0,
        can_scroll: false,
        showsearchparam: false,
        showsearch:false,
        showTop:false,
        searchlist:[],
        number:0,
        choosetaskmodel:{},
        optionName:'',
        choosesortmodel:{},
        option2: [],
        option3: [
            // { text: '排序', value: 0 },
            { text: '时间近到远', value: 1 },
            { text: '时间远到近', value: 2 },
        ],
        OrderByType:0,
    },
    methods: {
        get_data: function () {
            var that = this;
            that.is_searching = true;
            that.can_scroll = false;
            var options = {};
            options.action = "getmyinternaltask";
            options.pagesize = that.form.pagesize;
            options.pageindex = that.form.pageindex;
            options.OrderByType = that.OrderByType;
            options.Status = that.form.status;
            console.log(JSON.stringify(options));
            ns.post(options, function (succeed, data, err) {
                console.log(JSON.stringify(data));
                that.is_searching = false;
                if (succeed) {
                    if (data.list.length == that.form.pagesize) {
                        that.can_scroll = true;
                    }
                    if (that.form.pageindex == 0) {
                        that.searchlist = data.list;
                    } else {
                        that.searchlist = that.searchlist.concat(data.list);
                    }

                    that.current_item_length = that.searchlist.length;

                    that.form.isFirstLoad = 0;
                    
                } else if (err) {
                    that.current_item_length = 0;
                    api.toast({
                        msg: err,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            }, {
                toast: true
            });
        },
        //翻页第一条数据的位置
    //     do_scrollbtn:function(id){
    // 　　　　 var sollid = document.getElementById('scroll'+id);
    // 　　　　 window.scrollTo(0,sollid.offsetTop); 
    // 　　},
    //获取筛选条件
    get_menuType:function(){
        var that=this;
        var options = {};
        options.action = 'getmyinternaltaskparams';
        ns.post(options, function (succeed, data, err) {
            if(succeed){
                if(data.status){
                    that.option2=data.list;
                    that.choosetaskmodel=data.list[2];
                    that.optionName=that.choosetaskmodel.Name+'('+that.choosetaskmodel.Number+')';
                    that.choosesortmodel=that.option3[0];
                }
            }else{
                api.toast({
                    msg: err,
                    duration: 2000,
                    location: 'bottom'
                });
            }
        })
    },
    onChooseTask:function(item){
        var that = this;
        that.choosetaskmodel=item;
        that.optionName=that.choosetaskmodel.Name+'('+that.choosetaskmodel.Number+')';
        this.$refs.choosetask.toggle();
        that.form.status=item.Type;
        that.get_data();
    },
    onChooseSort:function(item){
        var that = this;
        that.choosesortmodel=item;
        this.$refs.choosesort.toggle();
        that.OrderByType=item.value;
        that.get_data();
    },
        do_open_detail: function (item) {
            var that = this;
            ns.openWin('neibutz_detail_frm', '内部通知详情', {
                id: item.ID,
                ids: item.IDs || 0,
                IsRead: item.IsRead,
                TypeStatus: that.form.status
            });
        },
        doHideSearch: function () {
            var that = this;
            that.showsearchparam = false;
            that.showsearch = false;
        },
        // 确认收到
        do_getok: function (item) {
            var that = this;
            var options = {};
            options.IDs = item.IDs;
            options.tdRemark='收到';
            options.action = "savanotificationread";
            ns.post(options, function (succeed, data, err) {
                if (succeed) {  

                    that.get_data();

                } else if (err) {
                    api.toast({
                        msg: err,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            });
        },
        open_select:function(){
            var that=this;
            that.showTop=!that.showTop;
        },
        doHideSearch:function(){
            var that=this;
            that.showTop=false;
            that.showsearch=false;
        },
        get_NoRead:function(){
            var that=this;
            var options = {};
            options.action = "getinternallist";
            options.pagesize = 1000;
            options.pageindex =0;
            options.Keywords = that.form.keywords;
            options.Initiated = 0;
            options.IsRead = 0;
            ns.post(options, function (succeed, data, err) {
                that.is_searching = false;
                if (succeed) {
                    that.searchlist = data.data;  
                    that.number=  that.searchlist.length;
                } else if (err) {
                    api.toast({
                        msg: err,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            }, {
                toast: true
            });
        },
        select_allstatus:function(){
            var that=this;
            that.showsearch=!that.showsearch;
            that.get_NoRead();
        },
        //搜索结果返回位置
        do_scrollTo:function(){
            var that = this;
    　　　　 var sollid = document.getElementById('scroll'+that.form.ID);
    　　　　 window.scrollTo(0,sollid.offsetTop); 
            var classlist=document.getElementById('scroll'+that.form.ID).getElementsByClassName('boxbg')[0];
            classlist.style.backgroundColor = "#eaf1ff";
            setTimeout(function() {
                classlist.style.backgroundColor = "#f7fbff";
            }, 800)
            
    　　},
    }
});
apiready = function () {
    api.parseTapmode();
    ns = window.Foresight.Util;
    dialog = new auiDialog();
    toast = new auiToast();
    app.get_menuType();
    app.form.ID = api.pageParam.ID || 0;

    api.addEventListener({
        name: 'reloadneibulist'
    }, function (ret, err) {
        app.form.isFirstLoad = 1;
        app.get_data();
    });
    ns.init_pull();
    app.get_data();
};
